#!/bin/bash

# Depends:
#     $WKSPACE
#     $USER
#     $SERVER_ADDR
source ${0%/*}/../config.local.sh

if [ $# != 2 ]; then
    echo UML.sh MD_PATH PNG_PATH.png
    exit
fi

if [ ! -f $1 ]; then
    echo Invalid input path: $1
    exit
fi

srcFile=`basename $1`
workspace=$WKSPACE/uml

scp $1 $USER@$SERVER_ADDR:$workspace
ssh $USER@$SERVER_ADDR "plantuml $workspace/$srcFile"
scp $USER@$SERVER_ADDR:$workspace/*.png $2
ssh $USER@$SERVER_ADDR "rm -rf $workspace/*"

if [ -f $2 ]; then
    echo Successfully generate UML: $2
else
    echo Failed handle UML from $1 to $2
fi
